<%
  selector_edit = "div##{dom_id(@project, 'edit')}"
  selector_edit = "div.project-edit-current " + selector_edit unless @source_view=="project"
  selector_project = "div##{dom_id(@project)}"
  selector_project = "div.project-edit-current " + selector_project unless @source_view=="project"
  object_name = unique_object_name_for("edit_project_#{@project.id}")
-%>
var <%=object_name%> = {
  animate: function() {
    <%=object_name%>.replace_project_with_edit_form();
  },
  replace_project_with_edit_form: function() {
    $('<%= selector_project %>').fadeOut(250, function() {
      <%=object_name%>.show_edit_form();
      <%=object_name%>.set_focus();
    });
  },
  show_edit_form: function() {
    $('<%= selector_edit %>').html(<%=object_name%>.html_for_edit_form());
    $('<%= selector_edit %>').fadeIn(500);
    $('span#project_name').editable('disable');
  },
  set_focus: function() {
    $('input.project-name').focus();
  },
  html_for_edit_form: function() {
    return "<%= js_render('project_form', {}, @project) %>";
  }
}

<%=object_name%>.animate();
